package com.angle.im.client.login;

import com.angle.im.client.fallback.ImFeignClientFallback;
import com.angle.im.common.utils.MessageModel;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhangwei
 * @date 2019/4/15 15:28
 * @desc
 */
@FeignClient(name = "im", fallback = ImFeignClientFallback.class)
public interface ImFeignClient {

    /**
     * token校验流程:
     * 1. client请求对应业务服务
     * 2. 业务服务请求IM系统,获取token
     * 3. IM系统保存token,并根据业务传过来的有效时间设置token有效期
     * 4. 将token返回给客户端
     * 2. client根据token连接服务
     */
    @RequestMapping(value = "auth/token", method = RequestMethod.PUT)
    @ResponseBody
    MessageModel getToken(@RequestParam("id") String userId);

    /**
     * 向单个用户发送消息
     *
     * @param to   用户id
     * @param msg  消息
     * @param save 是否需要保存,默认否
     * @return
     */
    @RequestMapping(value = "auth/sendOne", method = RequestMethod.POST)
    @ResponseBody
    MessageModel sendOne(@RequestHeader String token, @RequestParam String to, @RequestParam String msg, @RequestParam(defaultValue = "false") boolean save);

    /**
     * 向用户列表发送消息
     *
     * @param toList 用户id列表
     * @param msg    消息
     * @param save   是否需要保存,默认否
     * @return
     */
    @RequestMapping(value = "auth/sendList", method = RequestMethod.POST)
    @ResponseBody
    MessageModel sendList(@RequestHeader String token, @RequestParam List<String> toList, @RequestParam String msg, @RequestParam(defaultValue = "false") boolean save);
}
